#pragma once

#include <iostream>
#include <unistd.h>
#include <string>
#include <pthread.h>


class mutex
{
public:
    mutex(pthread_mutex_t* pmutex):_pmutex(pmutex)
    {
        pthread_mutex_init(_pmutex, nullptr);
    }

    void lock()
    {
        pthread_mutex_lock(_pmutex);
        //std::cout << "加锁成功" << std::endl;
    }

    void unlock()
    {
        pthread_mutex_unlock(_pmutex);
        //std::cout << "解锁成功" << std::endl;
    }

    ~mutex()
    {
        pthread_mutex_destroy(_pmutex);
    }

public:
    pthread_mutex_t *_pmutex;
};


class lockGuard
{
public:
    lockGuard(pthread_mutex_t *mutex):_mutex(mutex)
    {
        
        _mutex.lock();
    }

    ~lockGuard()
    {
        _mutex.unlock();
    }

private:
    mutex _mutex;
};